using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VPRARTAD
    {
        public DataRow Convert2PRARTAD(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryPRARTAD(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["PRAAMANDANT"] = " ".PadRight(2 ); 
         dwReturn["PRAAKOLL"] = " ".PadRight(5 ); 
         dwReturn["PRAAPRGRP"] = " ".PadRight(8 ); 
         dwReturn["PRAALFDNR"] = " ".PadRight(3 ); 
         dwReturn["PRAAART"] = " ".PadRight(24 ); 
         dwReturn["PRAAZUART"] = " ".PadRight(1 ); 
         dwReturn["PRAAZUNR"] = " ".PadRight(10 ); 
         dwReturn["PRAAPROZKZ"] = " ".PadRight(1 ); 
         dwReturn["PRAABASIS"] = " ".PadRight(1 ); 
         dwReturn["PRAAZUSCHL"] = " ".PadRight(3 ); 
         dwReturn["PRAAZUABWERT1"] = " ".PadRight(9 ); 
         dwReturn["PRAAZUABWERT2"] = " ".PadRight(9 ); 
         dwReturn["PRAAZUABWERT3"] = " ".PadRight(9 ); 
         dwReturn["PRAAZUABWERT4"] = " ".PadRight(9 ); 
         dwReturn["PRAAZUABWERT5"] = " ".PadRight(9 ); 
         dwReturn["PRAAAENDZL"] = " ".PadRight(3 ); 
         dwReturn["PRAAAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["PRAAAENDDAT"] = " ".PadRight(6 ); 
         dwReturn["PRAANEUBEN"] = " ".PadRight(8 ); 
         dwReturn["PRAANEUDAT"] = " ".PadRight(6 ); 
         dwReturn["PRAAFILLER"] = " ".PadRight(116 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapPRARTAD(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SavePRARTAD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryPRARTAD(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapPRARTAD(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertPRARTAD(dwLocal, ITXDBVERSION);
            }
            UpdatePRARTAD(dwLocal);
        }
        public void InsertPRARTAD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO PRARTAD(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryPRARTAD(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM PRARTAD WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM PRARTAD  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "PRARTAD";
            Return = Result;
            return Return;
        }
        public void DeletePRARTAD(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM PRARTAD   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdatePRARTAD(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE PRARTAD SET "
                    +"PRAAMANDANT= :PRAAMANDANT,"
                    +"PRAAKOLL= :PRAAKOLL,"
                    +"PRAAPRGRP= :PRAAPRGRP,"
                    +"PRAALFDNR= :PRAALFDNR,"
                    +"PRAAART= :PRAAART,"
                    +"PRAAZUART= :PRAAZUART,"
                    +"PRAAZUNR= :PRAAZUNR,"
                    +"PRAAPROZKZ= :PRAAPROZKZ,"
                    +"PRAABASIS= :PRAABASIS,"
                    +"PRAAZUSCHL= :PRAAZUSCHL,"
                    +"PRAAZUABWERT1= :PRAAZUABWERT1,"
                    +"PRAAZUABWERT2= :PRAAZUABWERT2,"
                    +"PRAAZUABWERT3= :PRAAZUABWERT3,"
                    +"PRAAZUABWERT4= :PRAAZUABWERT4,"
                    +"PRAAZUABWERT5= :PRAAZUABWERT5,"
                    +"PRAAAENDZL= :PRAAAENDZL,"
                    +"PRAAAENDBEN= :PRAAAENDBEN,"
                    +"PRAAAENDDAT= :PRAAAENDDAT,"
                    +"PRAANEUBEN= :PRAANEUBEN,"
                    +"PRAANEUDAT= :PRAANEUDAT,"
                    +"PRAAFILLER= :PRAAFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("PRAAMANDANT", OracleType.NVarChar).Value = dwData["PRAAMANDANT"].ToString(); 
          or1.Parameters.Add("PRAAKOLL", OracleType.NVarChar).Value = dwData["PRAAKOLL"].ToString(); 
          or1.Parameters.Add("PRAAPRGRP", OracleType.NVarChar).Value = dwData["PRAAPRGRP"].ToString(); 
          or1.Parameters.Add("PRAALFDNR", OracleType.NVarChar).Value = dwData["PRAALFDNR"].ToString(); 
          or1.Parameters.Add("PRAAART", OracleType.NVarChar).Value = dwData["PRAAART"].ToString(); 
          or1.Parameters.Add("PRAAZUART", OracleType.NVarChar).Value = dwData["PRAAZUART"].ToString(); 
          or1.Parameters.Add("PRAAZUNR", OracleType.NVarChar).Value = dwData["PRAAZUNR"].ToString(); 
          or1.Parameters.Add("PRAAPROZKZ", OracleType.NVarChar).Value = dwData["PRAAPROZKZ"].ToString(); 
          or1.Parameters.Add("PRAABASIS", OracleType.NVarChar).Value = dwData["PRAABASIS"].ToString(); 
          or1.Parameters.Add("PRAAZUSCHL", OracleType.NVarChar).Value = dwData["PRAAZUSCHL"].ToString(); 
          or1.Parameters.Add("PRAAZUABWERT1", OracleType.NVarChar).Value = dwData["PRAAZUABWERT1"].ToString(); 
          or1.Parameters.Add("PRAAZUABWERT2", OracleType.NVarChar).Value = dwData["PRAAZUABWERT2"].ToString(); 
          or1.Parameters.Add("PRAAZUABWERT3", OracleType.NVarChar).Value = dwData["PRAAZUABWERT3"].ToString(); 
          or1.Parameters.Add("PRAAZUABWERT4", OracleType.NVarChar).Value = dwData["PRAAZUABWERT4"].ToString(); 
          or1.Parameters.Add("PRAAZUABWERT5", OracleType.NVarChar).Value = dwData["PRAAZUABWERT5"].ToString(); 
          or1.Parameters.Add("PRAAAENDZL", OracleType.NVarChar).Value = dwData["PRAAAENDZL"].ToString(); 
          or1.Parameters.Add("PRAAAENDBEN", OracleType.NVarChar).Value = dwData["PRAAAENDBEN"].ToString(); 
          or1.Parameters.Add("PRAAAENDDAT", OracleType.NVarChar).Value = dwData["PRAAAENDDAT"].ToString(); 
          or1.Parameters.Add("PRAANEUBEN", OracleType.NVarChar).Value = dwData["PRAANEUBEN"].ToString(); 
          or1.Parameters.Add("PRAANEUDAT", OracleType.NVarChar).Value = dwData["PRAANEUDAT"].ToString(); 
          or1.Parameters.Add("PRAAFILLER", OracleType.NVarChar).Value = dwData["PRAAFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
